{extend name="../../admin/view/table"}

{block name="button"}
<!--{if auth("add")}-->
<button class='layui-btn layui-btn-sm layui-btn-primary' data-open='{:url("add")}' data-title="添加商品">添加商品</button>
<!--{/if}-->

{/block}

{block name="content"}

<div class="think-box-shadow">
    {include file='product/shop/index_search'}
    <table id="FormTable" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
</div>
{/block}

{block name='script'}

<script>
    $(function () {
        $('#FormTable').layTable({
            even: true, height: 'full',height: 'full',limit:20, //page:true,limit:20,
            //sort: {field: 'sort desc,id', type: 'asc'},
            //where: {type: '{$type|default="index"}'},
            cols: [[
                {checkbox: true, field: 'id'},
                {field: 'sort', title: '排序权重', width: 100, align: 'center', sort: true, templet: '#SortInputTpl'},
                {field: 'name', title: '商品名称', minWidth: 160},
                {field: 'cat', title: '类别', minWidth: 160},
                {field: 'create_time', title: '创建时间', minWidth: 170, align: 'center'},
                {field: 'status', title: '状态', minWidth: 120, align: 'center', templet: '#StatusSwitchTpl'},
                {toolbar: '#toolbar', title: '操作面板', minWidth: 150, align: 'center', fixed: 'right'},
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (object) {
            console.log(object);
            object.data = {status: object.elem.checked == 0 ? 1 : 0};
            object.data.id = object.value.split('|')[object.data.status] || object.value;console.log(object.data);
            $.form.load("{:url('state')}", object.data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#FormTable').trigger('reload');
                }); else {
                    $('#FormTable').trigger('reload');
                }
                return false;
            }, false);
        });
        
    });
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}|{{d.spp}}" lay-text="已上架|已下架" lay-filter="StatusSwitch" lay-skin="switch" {{-d.status==0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">已上架</b>' : '<b class="color-red">已下架</b>'}}
    <!--{/if}-->
</script>

<!-- 列表排序权重模板 -->
<script type="text/html" id="SortInputTpl">
    <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>

<!-- 操控面板的模板 -->
<script type="text/html" id="toolbar">


    <!--{if auth('edit')}-->
    <a class="layui-btn layui-btn-sm" data-title="编辑商品分类" data-open='{:url("edit")}?id={{d.id}}'>编 辑</a>
   
    <!--{/if}-->
    
</script>
{/block}
